//
//  ZYResourceCircleTowController.m
//  优学荟管理系统
//
//  Created by edz on 2017/11/8.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "ZYResourceCircleTowController.h"
#import "ZYResourceCircleTowModel.h"
#import "ZYResourceCircleTowCell.h"
#define kCell @"cell"
#import <PNChart.h>
#import "HNSalesManCycleDetailDateView.h"
#import "LLNavigationMidSearchItem.h"
#import "HMElementSortVC.h"
#import "ZYResourceSSSSController.h"

@interface ZYResourceCircleTowController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,CustomAlertDelegete>
{
    PNPieChart *_PieChart;
    NSInteger _mark;//标记类型
    NSString *_selectDate;//标记选中的日期
}
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIView *allView;
@property (nonatomic,assign) BOOL isTrue;
@property (nonatomic,assign) NSInteger page;
@property (nonatomic,copy) NSString *startTime;
@property (nonatomic,copy) NSString *endTime;
@property (nonatomic,copy) NSString *searchName;

@property (nonatomic,assign) BOOL isSure;
@property (nonatomic,assign) BOOL isSearch;



@property (nonatomic,strong) UIView *allTowView;
@property (nonatomic,strong) UIImageView *photoImageView;//机构图片
@property (nonatomic,strong) UILabel *mechanismLabel;//机构
@property (nonatomic,strong) UILabel *recommentdedCodeLabel;//推荐码
@property (nonatomic,strong) UIButton *photoAddButton;
@property (nonatomic,strong) UILabel *addressLabel;//地址



@property (nonatomic,strong) UILabel *startLabel;//开始时间
@property (nonatomic,strong) UIButton *startSelectButton;//选择开始时间
@property (nonatomic,strong) UILabel *endLabel;//结束时间
@property (nonatomic,strong) UIButton *endSelectButton;//选择结束时间

@property (nonatomic,strong) UIButton *sureButton;//确定
@property (nonatomic,strong) UILabel *institutionalRoyaltyLabel;//机构提出
@property (nonatomic,strong) UIButton *detailTowButton;//详情2







@property (nonatomic,strong) UIView *allThreeView;//




@property (nonatomic,strong) UIButton *greenButton;
@property (nonatomic,strong) UIButton *yellowButton;
@property (nonatomic,strong) UIButton *redButton;


@property(nonatomic,strong) UIView *allFourView; //172
@property(nonatomic,strong) UILabel *tiChengCountLabel;//机构提成金额
@property(nonatomic,strong) UILabel *jiaoFeiLabel;//缴费评价
@property(nonatomic,strong) UILabel *pingJiaZongLabel;//评价总次数
@property(nonatomic,strong) UILabel *usePingJiaZongLabel;//有效评价总次数
@property(nonatomic,strong) UILabel *jiaoFeiNoLabel;//暂无缴费有评价
@property(nonatomic,strong) UILabel *noPingJiaZongLabel;//暂无缴费评价总次数
@property(nonatomic,strong) UILabel *noJiaoFeiNoLabel;//暂无缴费有效评价总次数


@property(nonatomic,strong) UIView *allFiveView; //172
@property(nonatomic,strong) UILabel *teacherTiChengCountLabel;//老师提成金额
@property(nonatomic,strong) UILabel *teacherJiaoFeiLabel;//老师缴费评价
@property(nonatomic,strong) UILabel *teacherPingJiaZongLabel;//老师评价总次数
@property(nonatomic,strong) UILabel *teacherUsePingJiaZongLabel;//老师有效评价总次数
@property(nonatomic,strong) UILabel *teacherJiaoFeiNoLabel;//老师暂无缴费评价
@property(nonatomic,strong) UILabel *teacherNoPingJiaZongLabel;//暂无缴费评价总次数
@property(nonatomic,strong) UILabel *teacherNoJiaoFeiNoLabel;//暂无缴费有效评价总次数



@property (nonatomic,strong) UISearchBar *searchBar;

@property (nonatomic,strong) LLNavigationMidSearchItem *midItem;
@property (nonatomic,strong) UITextField *searchTextField;




@property (nonatomic,strong) NSMutableDictionary *organizationInfoDict;
@property (nonatomic,strong) NSMutableArray *dataSource;
@property (nonatomic,strong) NSMutableArray *dataTowSource;

@property (nonatomic,strong) CustomDayDatePicker *datePicker;


@end

@implementation ZYResourceCircleTowController


- (NSMutableArray *)dataSource{
    
    if (_dataSource == nil) {
        self.dataSource = [NSMutableArray array];
    }
    
    return _dataSource;
    
}

- (NSMutableArray *)dataTowSource{
    
    if (_dataTowSource == nil) {
        self.dataTowSource = [NSMutableArray array];
    }
    
    return _dataTowSource;
    
    
}




- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpSuperView];
    self.midItem = [[LLNavigationMidSearchItem alloc]init];
    self.midItem.frame = CGRectMake(0, 0,260, 30);
    self.midItem.searchField.placeholder = @"   搜索课程";
    self.midItem.layer.cornerRadius = 15;
    self.midItem.clipsToBounds = YES;
    self.navigationItem.titleView =self. midItem;
    self.searchTextField = self.midItem.searchField;
    self.searchTextField.delegate = self;
    self.searchTextField.returnKeyType =  UIReturnKeySearch;
    [self setUpRefresh];
}



- (CustomDayDatePicker *)datePicker {
    
    if (_datePicker == nil) {
        self.datePicker = [[CustomDayDatePicker alloc]initWithFrame:CGRectMake(0, 20, kScreenWidth - 60, 140)];
        
    }
    
    
    return _datePicker;
}

#pragma mark --- 上拉加载和下拉刷新方法的实现
- (void)setUpRefresh{
    
    //下拉刷新
    self.tableView.mj_header  = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(downRefresh)];
    //自动更改透明度
    self.tableView.mj_header.automaticallyChangeAlpha = YES;
    //进入刷新状态
    [self.tableView.mj_header beginRefreshing];
    
    //上拉加载
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(upRefresh)];
    //结束头部刷新
    [self.tableView.mj_header endRefreshing];
    //结束尾部刷新
    [self.tableView.mj_footer endRefreshing];
    
    
}

/**
 *  上拉加载
 */
- (void)upRefresh{
    
    self.isTrue = NO;
    self.page++;
    [self setNetWork];
    
}
/**
 *  下拉刷新
 */

- (void)downRefresh{
    self.isTrue = YES;
    self.page = 1;
    [self setNetWork];
    
    
}


- (void)setUpSuperView{
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64)];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    self.tableView.estimatedRowHeight = 200;
    
    
    [self.tableView registerClass:[ZYResourceCircleTowCell class] forCellReuseIdentifier:kCell];
    self.tableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    
    
    self.tableView.contentInset = UIEdgeInsetsMake(-54, 0, 0, 0);
    
    self.allView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 520+172 + 44+44 +44 +172 +44+44+44)];
    self.tableView.tableHeaderView = self.allView;
    
    
    
    
    [self setUpTowSuperView];
    
    
    self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(40, 0, kScreenWidth - 80, 15)];
    
    self.searchBar.barStyle = UIBarStyleDefault;
    self.navigationItem.titleView = self.searchBar;
    
    
    
}




- (void)setNetWork{
    //http://192.168.0.113:8080/StarShine/ys/resource.do?action=getResourceByOrg&oid=1&startTime=&endTime=&searchName=初中&pageNumber=1
    
    NSString *oid = [AccountTool shareAccountTool].currentAccount.oid;
    
    NSString *url;
    
    if (self.isSure) {
        url = [NSString stringWithFormat:@"resource.do?action=getResourceByOrg2&oid=%@&time=%@&searchName=&pageNumber=%ld",oid,self.startTime,(long)self.page];
    }else if (self.isSearch){
        
    NSString   *urlTow = [NSString stringWithFormat:@"resource.do?action=getResourceByOrg&oid=%@&startTime=%@&endTime=%@&searchName=%@&pageNumber=%ld",oid,self.startTime,self.endTime,self.searchName,(long)self.page];
        
        
        url = [urlTow stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        
    }else{
        url = [NSString stringWithFormat:@"resource.do?action=getResourceByOrg&oid=%@&startTime=&endTime=&searchName=&pageNumber=%ld",oid,(long)self.page];
    }
    
    
    
    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    
    
    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD showWithStatus:LLLoading];
    
    [NetManager Get:LLBaseURL(url) Auth:YES Params:nil Success:^(id Obj) {
        [SVProgressHUD dismiss];
        if ([[Obj valueForKey:@"code"] integerValue] == 1000) {
            
            if (self.isTrue == YES) {
                [self.dataSource removeAllObjects];
            }
            
            
            NSDictionary *t = [Obj valueForKey:@"t"];
            
            
            NSArray *resourcePieDatas = [t valueForKey:@"resourcePieDatas"];
            
            NSString *totalMoney = [NSString stringWithFormat:@"%@",[t valueForKey:@"totalMoney"]];
            
            NSMutableArray *Arr = [NSMutableArray array];
            
            for (NSDictionary *dict in resourcePieDatas) {
                
                NSString *courseType = [dict valueForKey:@"courseType"];
                NSString *money = [NSString stringWithFormat:@"%@",[dict valueForKey:@"money"]];
                
                UIColor *Color = nil;
                if ([courseType isEqualToString:@"普通课程"]) {
                    
                    Color = ColorRGB(102, 201, 186);
                } else if ([courseType isEqualToString:@"加强课"]) {
                    
                    Color = ColorRGB(240, 152, 143);
                } else if ([courseType isEqualToString:@"套餐课程"]) {
                    
                    Color = ColorRGB(245, 204, 111);
                } else {
                    
                    Color = nil;
                }
                
                
                CGFloat aaa =  [money floatValue]/[totalMoney floatValue];
                NSString *Str = [NSString stringWithFormat:@"%.2f",aaa];
                aaa = [Str floatValue];
                aaa > 0 ? [Arr addObject:[PNPieChartDataItem dataItemWithValue:aaa color:Color description:aaa < 0.2f ? @"":[NSString stringWithFormat:@"￥%@",dict[@"money"]]]]:nil;
                
                
            }
            
            
            [_PieChart updateChartData:Arr];
            [_PieChart strokeChart];
            //               [[self PieChart] updateChartData:[self CycleDataWithModel:Model]];
    
            double orgMoney =[[NSString stringWithFormat:@"%@",[t valueForKey:@"orgMoney"]] doubleValue];
            double teaMoney = [[NSString stringWithFormat:@"%@",[t valueForKey:@"teaMoney"]] doubleValue];
            
  
            
//
            NSMutableAttributedString *hintStringTow=[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"机构结算：¥%.2f",(teaMoney + orgMoney)]];
            //获取要调整颜色的文字位置,调整颜色
            NSRange rangeTow=[[hintStringTow string]rangeOfString:@"机构结算："];
            [hintStringTow addAttribute:NSForegroundColorAttributeName value:ColorRGB(102, 102, 102) range:rangeTow];
            
            self.institutionalRoyaltyLabel.attributedText=hintStringTow;
            
            
            self.organizationInfoDict = [t valueForKey:@"organizationInfo"];
            [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:[self.organizationInfoDict valueForKey:@"picture"]] placeholderImage:[UIImage imageNamed:@"icon_jiguo_default"]];
            self.mechanismLabel.text = [NSString stringWithFormat:@"%@(%@)",[self.organizationInfoDict valueForKey:@"websiteName"],[self.organizationInfoDict valueForKey:@"representativeName"]];
            self.recommentdedCodeLabel.text = [NSString stringWithFormat:@"推荐码:JG%@",[self.organizationInfoDict valueForKey:@"id"]];
            self.addressLabel.text = [NSString stringWithFormat:@"%@",[self.organizationInfoDict valueForKey:@"address"]];
            
            
            self.tiChengCountLabel.text = [NSString stringWithFormat:@"¥%@",[t valueForKey:@"orgMoney"]];////机构提成金额
            self.jiaoFeiLabel.text = [NSString stringWithFormat:@"%@元",[t valueForKey:@"orgTotalSettleMoneyPay"]];//缴费评价
            self.pingJiaZongLabel.text = [NSString stringWithFormat:@"评价总次数： %@次",[t valueForKey:@"threeCommentCountPayTea"]];//评价总次数
            self.usePingJiaZongLabel.text = [NSString stringWithFormat:@"有效评价总次数： %@次",[t valueForKey:@"validThreeCommentCountPayTea"]];//有效评价总次数
            self.jiaoFeiNoLabel.text = [NSString stringWithFormat:@"%@元",[t valueForKey:@"orgTotalSettleMoneyNotPay"]];//暂无缴费有评价
            self.noPingJiaZongLabel.text = [NSString stringWithFormat:@"评价总次数： %@次",[t valueForKey:@"threeCommentCountNotPayTea"]];//暂无缴费评价总次数
            self.noJiaoFeiNoLabel.text = [NSString stringWithFormat:@"有效评价总次数： %@次",[t valueForKey:@"validThreeCommentCountNotPayTea"]];//暂无缴费有效评价总次数
            
            
            
            //orgMoney机构提成金额  缴费评价orgTotalSettleMoneyPay  缴费评价总次数threeCommentCountPay  有效评价总次数validThreeCommentCountPay
            
            //            未交费有评价orgTotalSettleMoneyNotPay 未缴费评价总次数threeCommentCountNotPay
            //            未交费有效评价总次数validThreeCommentCountNotPay
            //            老师提成金额teaMoney
            //            机构结算  teaMONEY+ orgMoney 业务员responsibleMoney
            //            @property (nonatomic,strong) UILabel *personInChargeLabel;//负责人结算
            //            @property (nonatomic,strong) UILabel *institutionalRoyaltyLabel;//机构提出
            
            
            
            self.teacherTiChengCountLabel.text = [NSString stringWithFormat:@"¥%@",[t valueForKey:@"teaMoney"]];////老师提成金额
            self.teacherJiaoFeiLabel.text = [NSString stringWithFormat:@"%@元",[t valueForKey:@"teaTotalSettleMoneyPay"]];//缴费评价
            self.teacherPingJiaZongLabel.text = [NSString stringWithFormat:@"评价总次数： %@次",[t valueForKey:@"threeCommentCountPayTea"]];//评价总次数
            self.teacherUsePingJiaZongLabel.text = [NSString stringWithFormat:@"有效评价总次数： %@次",[t valueForKey:@"validThreeCommentCountPayTea"]];//有效评价总次数
            self.teacherJiaoFeiNoLabel.text = [NSString stringWithFormat:@"%@元",[t valueForKey:@"teaTotalSettleMoneyNotPay"]];//暂无缴费有评价
            self.teacherNoPingJiaZongLabel.text = [NSString stringWithFormat:@"评价总次数： %@次",[t valueForKey:@"threeCommentCountNotPayTea"]];//暂无缴费评价总次数
            self.teacherNoJiaoFeiNoLabel.text = [NSString stringWithFormat:@"有效评价总次数： %@次",[t valueForKey:@"validThreeCommentCountNotPayTea"]];//暂无缴费有效评价总次数
            
            
            
            
            
            NSDictionary *dict = [t valueForKey:@"lessons"];
            NSArray *arr = [dict valueForKey:@"dataList"];
            for (NSDictionary *dicts in arr) {
                
                ZYResourceCircleTowModel *model = [ZYResourceCircleTowModel new];
                
                model.ID = [dicts valueForKey:@"id"];
                [model setValuesForKeysWithDictionary:dicts];
                
                [self.dataSource addObject:model];
            }
            
            
            
            [self.tableView reloadData];
            [self.tableView.mj_header endRefreshing];
            [self.tableView.mj_footer endRefreshing];
            
        }
        
        
        
        
    } Fail:^(NSError *Error) {
        
        [self.tableView.mj_footer endRefreshing];
        [self.tableView.mj_header endRefreshing];
        [SVProgressHUD dismiss];
        
    }];
    
    
    
    
}










#pragma mark ---所有自视图
- (void)setUpTowSuperView{
    
    
    
    
    //导航栏上的
    
    self.allTowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 110)];
    self.allTowView.backgroundColor  = ColorRGB(49, 204, 131);
    [self.allView addSubview:self.allTowView];
    
    self.photoImageView = [UIImageView new];
    self.photoImageView.layer.cornerRadius = 20;
    self.photoImageView.image = [UIImage imageNamed:@"icon_jiguo_default"];
    self.photoImageView.clipsToBounds = YES;
    [self.allTowView addSubview:self.photoImageView];
    
    [self.photoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10);
        make.top.offset(20);
        make.width.height.offset(40);
    }];
    
    self.mechanismLabel = [UILabel new];
    self.mechanismLabel.text = @"有的机构";
    self.mechanismLabel.textColor = ColorRGB(255, 255, 255);
    self.mechanismLabel.font = [UIFont systemFontOfSize:15];
    [self.allTowView addSubview:self.mechanismLabel];
    
    
    [self.mechanismLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.photoImageView.mas_right).offset(5);
        make.top.equalTo(self.photoImageView);
    }];
    
    self.recommentdedCodeLabel = [UILabel new];
    self.recommentdedCodeLabel.text = @"推荐码：skljglsgj";
    self.recommentdedCodeLabel.font = [UIFont systemFontOfSize:13];
    self.recommentdedCodeLabel.textColor = ColorRGB(255, 255, 255);
    [self.allTowView addSubview:self.recommentdedCodeLabel];
    
    
    [self.recommentdedCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mechanismLabel);
        make.top.equalTo(self.mechanismLabel.mas_bottom).offset(8);
        
    }];
    
    self.photoAddButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.photoAddButton setImage:[UIImage imageNamed:@"icon_map_default"] forState:(UIControlStateNormal)];
    [self.allTowView addSubview:self.photoAddButton];
    
    [self.photoAddButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.photoImageView);
        make.top.equalTo(self.photoImageView.mas_bottom).offset(8);
        make.width.height.equalTo(self.photoImageView);
    }];
    
    
    self.addressLabel = [UILabel new];
    self.addressLabel.font = [UIFont systemFontOfSize:13];
    self.addressLabel.textColor = ColorRGB(255, 255, 255);
    self.addressLabel.numberOfLines = 0;
    [self.allTowView addSubview:self.addressLabel];
    
//    self.addressLabel.text = @"深圳市宝安区账户深圳市宝安区账户深圳市宝安区账户深圳市宝安区账户";
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.photoAddButton.mas_right).offset(5);
        make.top.centerY.equalTo(self.photoAddButton);
        make.right.equalTo(self.allTowView).offset(-8);
    }];
    
    
    
    
    
    
    self.startLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, self.allTowView.frame.origin.y + self.allTowView.frame.size.height + 15, kScreenWidth - 140, 20)];
    self.startLabel.text = @"月份";
    self.startLabel.textColor = ColorRGB(127, 125, 125);
    self.startLabel.font = [UIFont systemFontOfSize:14];
    [self.allView addSubview:self.startLabel];
    
    
    self.startSelectButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.startSelectButton.frame = CGRectMake(kScreenWidth - 140,self.startLabel.frame.origin.y,120,20);
    [self.startSelectButton setImage:[UIImage imageNamed:@"icon_time_default"] forState:(UIControlStateNormal)];
    [self.startSelectButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    
    [self.startSelectButton setTitle:[NSString stringWithFormat:@"%@",[NSString getCurrentTime_HN]] forState:(UIControlStateNormal)];
    
    
    
    self.startSelectButton.titleLabel.font = [UIFont systemFontOfSize:14];
    self.startSelectButton.backgroundColor = ColorRGB(235, 250, 243);
    [self.allView addSubview:self.startSelectButton];
    
    
//    self.endLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.startLabel.frame.origin.x,self.startLabel.frame.origin.y + self.startLabel.frame.size.height + 15,self.startLabel.frame.size.width , self.startLabel.frame.size.height)];
//    self.endLabel.text = @"结束时间";
//    self.endLabel.textColor = ColorRGB(127, 125, 125);
//    self.endLabel.font = [UIFont systemFontOfSize:14];
//    [self.allView addSubview:self.self.endLabel];
    
//    self.endSelectButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
//    self.endSelectButton.frame = CGRectMake(self.startSelectButton.frame.origin.x,self.endLabel.frame.origin.y,self.startSelectButton.frame.size.width,self.startSelectButton.frame.size.height);
//    [self.endSelectButton setImage:[UIImage imageNamed:@"icon_time_default"] forState:(UIControlStateNormal)];
//    [self.endSelectButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
//
//
//    [self.endSelectButton setTitle:[NSString stringWithFormat:@"%@",[NSString yearMonthDay]] forState:(UIControlStateNormal)];
//    self.endSelectButton.titleLabel.font = [UIFont systemFontOfSize:14];
//    self.endSelectButton.backgroundColor = ColorRGB(235, 250, 243);
//    [self.allView addSubview:self.endSelectButton];
    
    
    self.sureButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.sureButton.frame = CGRectMake(30, self.startSelectButton.frame.origin.y + self.startSelectButton.frame.size.height  + 30, kScreenWidth - 60, 30);
    [self.sureButton setTitle:@"确定" forState:(UIControlStateNormal)];
    
    [self.sureButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    self.sureButton.backgroundColor = ColorRGB(49, 204, 131);
    self.sureButton.layer.cornerRadius = 15;
    self.sureButton.clipsToBounds = YES;
    [self.allView addSubview:self.sureButton];
    
    
    UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.sureButton.frame.origin.y + self.sureButton.frame.size.height + 15, kScreenWidth, 3)];
    lineLabel.backgroundColor = ColorRGB(245, 245, 245);
    [self.allView addSubview:lineLabel];
    
    
    
    
    self.allThreeView = [[UIView alloc]initWithFrame:CGRectMake(0, lineLabel.frame.origin.y + lineLabel.frame.size.height + 15, kScreenWidth, 160)];
    
    //    self.allThreeView.backgroundColor = [UIColor purpleColor];
    [self.allView addSubview:self.allThreeView];
    
    //    NSArray *items = @[[PNPieChartDataItem dataItemWithValue:50 color:PNRed description:@"孔帅哥"],
    //                       [PNPieChartDataItem dataItemWithValue:20 color:PNBlue description:@"其他人"],
    //                       [PNPieChartDataItem dataItemWithValue:30 color:PNGreen description:@"未知"],
    //                       ];
    
    PNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectZero items:nil];
    pieChart.descriptionTextColor = [UIColor whiteColor];
    pieChart.descriptionTextFont  = [UIFont fontWithName:@"Avenir-Medium" size:14.0];
    _PieChart = pieChart;
    //[pieChart strokeChart];
    
    
    _PieChart.frame = CGRectMake(30, 10,140,140);
    [self.allThreeView addSubview:_PieChart];
    
    
    
    
    
    self.greenButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.greenButton.frame = CGRectMake(kScreenWidth - 120, 30, 100, 20);
    //    self.greenButton.backgroundColor = [UIColor greenColor];
    [self.greenButton setTitle:@" 普通课程" forState:(UIControlStateNormal)];
    self.greenButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.greenButton setImage:[UIImage imageNamed:@"green"] forState:(UIControlStateNormal)];
    [self.greenButton setTitleColor:ColorRGB(127, 125, 125) forState:(UIControlStateNormal)];
    self.greenButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.allThreeView addSubview:self.greenButton];
    
    self.yellowButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.yellowButton.frame = CGRectMake(self.greenButton.frame.origin.x,self.greenButton.frame.origin.y + self.greenButton.frame.size.height + 20, self.greenButton.frame.size.width, self.greenButton.frame.size.height);
    [self.yellowButton setImage:[UIImage imageNamed:@"yellow"] forState:(UIControlStateNormal)];
    //    self.yellowButton.backgroundColor = [UIColor yellowColor];
    [self.yellowButton setTitle:@" 套餐课程" forState:(UIControlStateNormal)];
    self.yellowButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.yellowButton setTitleColor:ColorRGB(127, 125, 125) forState:(UIControlStateNormal)];
    self.yellowButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.allThreeView addSubview:self.yellowButton];
    
    
    
    self.redButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.redButton.frame = CGRectMake(self.yellowButton.frame.origin.x, self.yellowButton.frame.origin.y + self.yellowButton.frame.size.height + 20, self.yellowButton.frame.size.width, self.yellowButton.frame.size.height);
    [self.redButton setTitle:@" 加强课程" forState:(UIControlStateNormal)];
    self.redButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.redButton setTitleColor:ColorRGB(127, 125, 125) forState:(UIControlStateNormal)];
    [self.redButton setImage:[UIImage imageNamed:@"red"] forState:(UIControlStateNormal)];
    self.redButton.titleLabel.font = [UIFont systemFontOfSize:13];
    //    self.redButton.backgroundColor = [UIColor redColor];
    [self.allThreeView addSubview:self.redButton];
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    UILabel *lineTowLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.allThreeView.frame.origin.y + self.allThreeView.frame.size.height + 15, kScreenWidth, 3)];
    lineTowLabel.backgroundColor = ColorRGB(245, 245, 245);
    [self.allView addSubview:lineTowLabel];
    
    
    //从这里加
    self.allFourView = [[UIView alloc]initWithFrame:CGRectMake(0, lineTowLabel.frame.origin.y+lineTowLabel.frame.size.height, kScreenWidth, 172)];
    self.allFourView.backgroundColor = [UIColor clearColor];
    [self.allView addSubview:_allFourView];
    
    UILabel *yeWuLabel = [UILabel new];
    yeWuLabel.text = @"业务详情";
    yeWuLabel.textColor = ColorRGB(51, 51, 51);
    yeWuLabel.font = [UIFont systemFontOfSize:17];
    [self.allFourView addSubview:yeWuLabel];
    [yeWuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.allFourView).offset(20);
        
    }];
    
    UILabel *tiChengLabel = [UILabel new];
    tiChengLabel.text = @"机构提成金额";
    tiChengLabel.textColor = ColorRGB(102, 102, 102);
    tiChengLabel.font = [UIFont systemFontOfSize:13];
    [self.allFourView addSubview:tiChengLabel];
    [tiChengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(yeWuLabel.mas_bottom).offset(20);
        make.centerX.equalTo(self.allFourView);
        
    }];
    
    self.tiChengCountLabel = [UILabel new];
    self.tiChengCountLabel.text = @"";
    self.tiChengCountLabel.textColor = ColorRGB(255, 51, 51);
    self.tiChengCountLabel.font  = [UIFont systemFontOfSize:27];
    [self.allFourView addSubview:self.tiChengCountLabel];
    [self.tiChengCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tiChengLabel.mas_bottom).offset(10);
        make.centerX.equalTo(self.allFourView);
    }];
    
    UIImageView *yeWuImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_zijing"]];
    [self.allFourView addSubview:yeWuImageView];
    [yeWuImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tiChengCountLabel.mas_bottom).offset(21);
        make.left.offset(21);
    }];
    
    UILabel *jiaofei1Label = [UILabel new];
    jiaofei1Label.text = @"缴费评价:";
    jiaofei1Label.font = [UIFont systemFontOfSize:17];
    jiaofei1Label.textColor = ColorRGB(51, 51, 51);
    [self.allFourView addSubview:jiaofei1Label];
    [jiaofei1Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(yeWuImageView.mas_centerY);
        make.left.equalTo(yeWuImageView.mas_right).offset(11);
    }];
    
    self.jiaoFeiLabel = [UILabel new];
    self.jiaoFeiLabel.text = @"100元";
    self.jiaoFeiLabel.font = [UIFont systemFontOfSize:17];
    self.jiaoFeiLabel.textColor = ColorRGB(51, 51, 51);
    [self.allFourView addSubview:self.jiaoFeiLabel];
    [self.jiaoFeiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(jiaofei1Label.mas_right).offset(10);
        make.centerY.equalTo(jiaofei1Label);
    }];
    
    
    UIView *pingJiaView = [UIView new];
    pingJiaView.backgroundColor = [UIColor clearColor];
    pingJiaView.frame = CGRectMake(0, self.allFourView.frame.size.height + self.allFourView.frame.origin.y, kScreenWidth, 44);
    [self.allView addSubview:pingJiaView];
    pingJiaView.backgroundColor = [UIColor clearColor];
    
    UIView *pjOneline = [UIView new];
    pjOneline.frame = CGRectMake(0, 0, kScreenWidth, 1);
    pjOneline.backgroundColor = ColorRGB(242, 244, 246);
    [pingJiaView addSubview:pjOneline];
    
    UIView *pjTwoline = [UIView new];
    pjTwoline.frame = CGRectMake(0, pingJiaView.bounds.size.height +pingJiaView.bounds.origin.y - 1, kScreenWidth, 1);
    pjTwoline.backgroundColor = ColorRGB(242, 244, 246);
    [pingJiaView addSubview:pjTwoline];
    
    
    self.pingJiaZongLabel = [UILabel new];
    self.pingJiaZongLabel.text = @"评价总次数: 100次";
    self.pingJiaZongLabel.textAlignment = NSTextAlignmentCenter;
    self.pingJiaZongLabel.textColor = ColorRGB(153, 153, 153);
    self.pingJiaZongLabel.font = [UIFont systemFontOfSize:14];
    self.pingJiaZongLabel.frame = CGRectMake(0, 0, pingJiaView.bounds.size.width/2, 44);
    [pingJiaView addSubview:self.pingJiaZongLabel];
    
    self.usePingJiaZongLabel = [UILabel new];
    self.usePingJiaZongLabel.text = @"有效评价总次数: 100次";
    self.usePingJiaZongLabel.textColor = ColorRGB(153, 153, 153);
    self.usePingJiaZongLabel.font = [UIFont systemFontOfSize:14];
    self.usePingJiaZongLabel.textAlignment = NSTextAlignmentCenter;
    self.usePingJiaZongLabel.frame = CGRectMake(pingJiaView.bounds.size.width/2, 0, pingJiaView.bounds.size.width/2, 44);
    [pingJiaView addSubview:self.usePingJiaZongLabel];
    
    //机构暂无缴费有评价
    UIView *yeWuNoView = [UIView new];
    yeWuNoView.backgroundColor = [UIColor clearColor];
    yeWuNoView.frame = CGRectMake(0, pingJiaView.frame.origin.y + pingJiaView.frame.size.height, kScreenWidth, 44);
    [self.allView addSubview:yeWuNoView];
    
    UIImageView *yeWuNoImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_zijing_two"]];
    [yeWuNoView addSubview:yeWuNoImageView];
    [yeWuNoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(yeWuNoView);
        make.left.offset(21);
    }];
    
    
    UILabel *jiaofeiNo1Label = [UILabel new];
    jiaofeiNo1Label.text = @"暂无缴费有评价:";
    jiaofeiNo1Label.font = [UIFont systemFontOfSize:17];
    jiaofeiNo1Label.textColor = ColorRGB(51, 51, 51);
    [yeWuNoView addSubview:jiaofeiNo1Label];
    [jiaofeiNo1Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(yeWuNoImageView.mas_centerY);
        make.left.equalTo(yeWuNoImageView.mas_right).offset(11);
    }];
    
    self.jiaoFeiNoLabel = [UILabel new];
    self.jiaoFeiNoLabel.text = @"100元";
    self.jiaoFeiNoLabel.font = [UIFont systemFontOfSize:17];
    self.jiaoFeiNoLabel.textColor = ColorRGB(51, 51, 51);
    [yeWuNoView addSubview:self.jiaoFeiNoLabel];
    [self.jiaoFeiNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(jiaofeiNo1Label.mas_right).offset(10);
        make.centerY.equalTo(jiaofeiNo1Label);
    }];
    
    UIView *noJiGouPingJiaView = [UIView new];
    noJiGouPingJiaView.backgroundColor = [UIColor clearColor];
    noJiGouPingJiaView.frame = CGRectMake(0, yeWuNoView.frame.size.height + yeWuNoView.frame.origin.y, kScreenWidth, 44);
    [self.allView addSubview:noJiGouPingJiaView];
    
    
    
    UIView *noPjOneline = [UIView new];
    noPjOneline.frame = CGRectMake(0, 0, kScreenWidth, 1);
    noPjOneline.backgroundColor = ColorRGB(242, 244, 246);
    [noJiGouPingJiaView addSubview:noPjOneline];
    //
    UIView *noPjTwoline = [UIView new];
    noPjTwoline.frame = CGRectMake(0, noJiGouPingJiaView.bounds.size.height +noJiGouPingJiaView.bounds.origin.y - 1, kScreenWidth, 1);
    noPjTwoline.backgroundColor = ColorRGB(242, 244, 246);
    [noJiGouPingJiaView addSubview:noPjTwoline];
    
    
    self.noPingJiaZongLabel = [UILabel new];
    self.noPingJiaZongLabel.text = @"评价总次数: 100次";
    self.noPingJiaZongLabel.textAlignment = NSTextAlignmentCenter;
    self.noPingJiaZongLabel.textColor = ColorRGB(153, 153, 153);
    self.noPingJiaZongLabel.font = [UIFont systemFontOfSize:14];
    self.noPingJiaZongLabel.frame = CGRectMake(0, 0, noJiGouPingJiaView.bounds.size.width/2, 44);
    [noJiGouPingJiaView addSubview:self.noPingJiaZongLabel];
    
    self.noJiaoFeiNoLabel = [UILabel new];
    self.noJiaoFeiNoLabel.text = @"有效评价总次数: 100次";
    self.noJiaoFeiNoLabel.textColor = ColorRGB(153, 153, 153);
    self.noJiaoFeiNoLabel.font = [UIFont systemFontOfSize:14];
    self.noJiaoFeiNoLabel.textAlignment = NSTextAlignmentCenter;
    self.noJiaoFeiNoLabel.frame = CGRectMake(pingJiaView.bounds.size.width/2, 0, pingJiaView.bounds.size.width/2, 44);
    [noJiGouPingJiaView addSubview:self.noJiaoFeiNoLabel];
    
    
    
    //老师业务详情
    self.allFiveView = [[UIView alloc]initWithFrame:CGRectMake(0, noJiGouPingJiaView.frame.origin.y+noJiGouPingJiaView.frame.size.height, kScreenWidth, 172)];
    self.allFiveView.backgroundColor = [UIColor clearColor];
    [self.allView addSubview:self.allFiveView];
    
    
    UIView *teacherLineView = [[UIView alloc]init];
    teacherLineView.backgroundColor = ColorRGB(242, 244, 246);
    teacherLineView.frame = CGRectMake(0, 0, kScreenWidth, 3);
    [self.allFiveView addSubview:teacherLineView];
    
    UILabel *teacherYeWuLabel = [UILabel new];
    teacherYeWuLabel.text = @"业务详情";
    teacherYeWuLabel.textColor = ColorRGB(51, 51, 51);
    teacherYeWuLabel.font = [UIFont systemFontOfSize:17];
    [self.allFiveView addSubview:teacherYeWuLabel];
    [teacherYeWuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.allFiveView).offset(20);
        
    }];
    
    UILabel *teacherTiChengLabel = [UILabel new];
    teacherTiChengLabel.text = @"老师提成金额";
    teacherTiChengLabel.textColor = ColorRGB(102, 102, 102);
    teacherTiChengLabel.font = [UIFont systemFontOfSize:13];
    [self.allFiveView addSubview:teacherTiChengLabel];
    [teacherTiChengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(teacherYeWuLabel.mas_bottom).offset(20);
        make.centerX.equalTo(self.allFiveView);
        
    }];
    
    self.teacherTiChengCountLabel = [UILabel new];
    self.teacherTiChengCountLabel.text = @"";
    self.teacherTiChengCountLabel.textColor = ColorRGB(255, 51, 51);
    self.teacherTiChengCountLabel.font  = [UIFont systemFontOfSize:27];
    [self.allFiveView addSubview:self.teacherTiChengCountLabel];
    [self.teacherTiChengCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(teacherTiChengLabel.mas_bottom).offset(10);
        make.centerX.equalTo(self.allFiveView);
    }];
    
    UIImageView *teacherImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_zijing"]];
    [self.allFiveView addSubview:teacherImageView];
    [teacherImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.teacherTiChengCountLabel.mas_bottom).offset(21);
        make.left.offset(21);
    }];
    
    UILabel *teacherJiaofei1Label = [UILabel new];
    teacherJiaofei1Label.text = @"缴费评价:";
    teacherJiaofei1Label.font = [UIFont systemFontOfSize:17];
    teacherJiaofei1Label.textColor = ColorRGB(51, 51, 51);
    [self.allFiveView addSubview:teacherJiaofei1Label];
    [teacherJiaofei1Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(teacherImageView.mas_centerY);
        make.left.equalTo(teacherImageView.mas_right).offset(11);
    }];
    
    self.teacherJiaoFeiLabel = [UILabel new];
    self.teacherJiaoFeiLabel.text = @"100元";
    self.teacherJiaoFeiLabel.font = [UIFont systemFontOfSize:17];
    self.teacherJiaoFeiLabel.textColor = ColorRGB(51, 51, 51);
    [self.allFiveView addSubview:self.teacherJiaoFeiLabel];
    [self.teacherJiaoFeiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(teacherJiaofei1Label.mas_right).offset(10);
        make.centerY.equalTo(teacherJiaofei1Label);
    }];
    
    UIView *teacherPingJiaView = [UIView new];
    teacherPingJiaView.backgroundColor = [UIColor clearColor];
    teacherPingJiaView.frame = CGRectMake(0, self.allFiveView.frame.size.height + self.allFiveView.frame.origin.y, kScreenWidth, 44);
    [self.allView addSubview:teacherPingJiaView];
    pingJiaView.backgroundColor = [UIColor clearColor];
    
    UIView *teacherPjOneline = [UIView new];
    teacherPjOneline.frame = CGRectMake(0, 0, kScreenWidth, 1);
    teacherPjOneline.backgroundColor = ColorRGB(242, 244, 246);
    [teacherPingJiaView addSubview:teacherPjOneline];
    
    UIView *teacherPjTwoline = [UIView new];
    teacherPjTwoline.frame = CGRectMake(0, teacherPingJiaView.bounds.size.height +teacherPingJiaView.bounds.origin.y - 1, kScreenWidth, 1);
    teacherPjTwoline.backgroundColor = ColorRGB(242, 244, 246);
    [teacherPingJiaView addSubview:teacherPjTwoline];
    
    self.teacherPingJiaZongLabel = [UILabel new];
    self.teacherPingJiaZongLabel.text = @"评价总次数: 100次";
    self.teacherPingJiaZongLabel.textAlignment = NSTextAlignmentCenter;
    self.teacherPingJiaZongLabel.textColor = ColorRGB(153, 153, 153);
    self.teacherPingJiaZongLabel.font = [UIFont systemFontOfSize:14];
    self.teacherPingJiaZongLabel.frame = CGRectMake(0, 0, teacherPingJiaView.bounds.size.width/2, 44);
    [teacherPingJiaView addSubview:self.teacherPingJiaZongLabel];
    
    self.teacherUsePingJiaZongLabel = [UILabel new];
    self.teacherUsePingJiaZongLabel.text = @"评价总次数: 100次";
    self.teacherUsePingJiaZongLabel.textColor = ColorRGB(153, 153, 153);
    self.teacherUsePingJiaZongLabel.font = [UIFont systemFontOfSize:14];
    self.teacherUsePingJiaZongLabel.textAlignment = NSTextAlignmentCenter;
    self.teacherUsePingJiaZongLabel.frame = CGRectMake(teacherPingJiaView.bounds.size.width/2, 0, teacherPingJiaView.bounds.size.width/2, 44);
    [teacherPingJiaView addSubview:self.teacherUsePingJiaZongLabel];
    
    
    //老师暂无缴费有评价
    UIView *teahcerNoView = [UIView new];
    teahcerNoView.backgroundColor = [UIColor clearColor];
    teahcerNoView.frame = CGRectMake(0, teacherPingJiaView.frame.origin.y + teacherPingJiaView.frame.size.height, kScreenWidth, 44);
    [self.allView addSubview:teahcerNoView];
    
    UIImageView *teacherNoImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_zijing_two"]];
    [teahcerNoView addSubview:teacherNoImageView];
    [teacherNoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(teahcerNoView);
        make.left.offset(21);
    }];
    
    UILabel *teacherJiaofeiNo1Label = [UILabel new];
    teacherJiaofeiNo1Label.text = @"暂无缴费有评价:";
    teacherJiaofeiNo1Label.font = [UIFont systemFontOfSize:17];
    teacherJiaofeiNo1Label.textColor = ColorRGB(51, 51, 51);
    [teahcerNoView addSubview:teacherJiaofeiNo1Label];
    [teacherJiaofeiNo1Label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(teacherNoImageView.mas_centerY);
        make.left.equalTo(teacherNoImageView.mas_right).offset(11);
    }];
    
    self.teacherJiaoFeiNoLabel = [UILabel new];
    self.teacherJiaoFeiNoLabel.text = @"100元";
    self.teacherJiaoFeiNoLabel.font = [UIFont systemFontOfSize:17];
    self.teacherJiaoFeiNoLabel.textColor = ColorRGB(51, 51, 51);
    [teahcerNoView addSubview:self.teacherJiaoFeiNoLabel];
    [self.teacherJiaoFeiNoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(teacherJiaofeiNo1Label.mas_right).offset(10);
        make.centerY.equalTo(teacherJiaofeiNo1Label);
    }];
    
    UIView *noTeacherPingJiaView = [UIView new];
    noTeacherPingJiaView.backgroundColor = [UIColor clearColor];
    noTeacherPingJiaView.frame = CGRectMake(0, teahcerNoView.frame.size.height + teahcerNoView.frame.origin.y, kScreenWidth, 44);
    [self.allView addSubview:noTeacherPingJiaView];
    
    UIView *noteacherPjOneline = [UIView new];
    noteacherPjOneline.frame = CGRectMake(0, 0, kScreenWidth, 1);
    noteacherPjOneline.backgroundColor = ColorRGB(242, 244, 246);
    [noTeacherPingJiaView addSubview:noteacherPjOneline];
    
    UIView *noteacherPjTwoline = [UIView new];
    noteacherPjTwoline.frame = CGRectMake(0, noTeacherPingJiaView.bounds.size.height +noTeacherPingJiaView.bounds.origin.y - 1, kScreenWidth, 1);
    noteacherPjTwoline.backgroundColor = ColorRGB(242, 244, 246);
    [noTeacherPingJiaView addSubview:noteacherPjTwoline];
    
    self.teacherNoPingJiaZongLabel = [UILabel new];
    self.teacherNoPingJiaZongLabel.text = @"评价总次数: 100次";
    self.teacherNoPingJiaZongLabel.textAlignment = NSTextAlignmentCenter;
    self.teacherNoPingJiaZongLabel.textColor = ColorRGB(153, 153, 153);
    self.teacherNoPingJiaZongLabel.font = [UIFont systemFontOfSize:14];
    self.teacherNoPingJiaZongLabel.frame = CGRectMake(0, 0, noTeacherPingJiaView.bounds.size.width/2, 44);
    [noTeacherPingJiaView addSubview:self.teacherNoPingJiaZongLabel];
    
    self.teacherNoJiaoFeiNoLabel = [UILabel new];
    self.teacherNoJiaoFeiNoLabel.text = @"有效评价总次数: 100次";
    self.teacherNoJiaoFeiNoLabel.textColor = ColorRGB(153, 153, 153);
    self.teacherNoJiaoFeiNoLabel.font = [UIFont systemFontOfSize:14];
    self.teacherNoJiaoFeiNoLabel.textAlignment = NSTextAlignmentCenter;
    self.teacherNoJiaoFeiNoLabel.frame = CGRectMake(pingJiaView.bounds.size.width/2, 0, pingJiaView.bounds.size.width/2, 44);
    [noTeacherPingJiaView addSubview:self.teacherNoJiaoFeiNoLabel];
    
    
    //机构提成
    self.institutionalRoyaltyLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, noTeacherPingJiaView.frame.origin.y + noTeacherPingJiaView.frame.size.height + 20, kScreenWidth - 100, 30)];
    self.institutionalRoyaltyLabel.font = [UIFont systemFontOfSize:15];
    self.institutionalRoyaltyLabel.textColor = [UIColor redColor];
    [self.allView addSubview:self.institutionalRoyaltyLabel];
    
    
    self.detailTowButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.detailTowButton.frame = CGRectMake(kScreenWidth - 100, self.institutionalRoyaltyLabel.frame.origin.y, 80, 30);
    [self.detailTowButton setTitle:@"结算历史" forState:(UIControlStateNormal)];
    self.detailTowButton.backgroundColor = ColorRGB(49, 204, 131);
    self.detailTowButton.layer.cornerRadius = 15;
    self.detailTowButton.clipsToBounds = YES;
    self.detailTowButton.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [self.detailTowButton setTitleColor:ColorRGB(252, 252, 252) forState:(UIControlStateNormal)];
    [self.allView addSubview:self.detailTowButton];
    
    
    
    
    
    
    
    
    UILabel *lineThreeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.detailTowButton.frame.origin.y + self.detailTowButton.frame.size.height + 15, kScreenWidth, 3)];
    lineThreeLabel.backgroundColor = ColorRGB(245, 245, 245);
    [self.allView addSubview:lineThreeLabel];
    
    
    
    
    
    
    
    
    
    self.startSelectButton.tag = 201;
//    self.endSelectButton.tag = 202;
    [self.startSelectButton addTarget:self action:@selector(allButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
//    [self.endSelectButton addTarget:self action:@selector(allButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.sureButton addTarget:self action:@selector(sureButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    self.detailTowButton.tag = 203;
    [self.detailTowButton addTarget:self action:@selector(allButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    
    
}



#pragma mark ---详情方法的实现
- (void)allButtonAction:(UIButton *)sender{
    
    NSInteger tag = sender.tag;
    
    if (201 == tag) {
        
        NSLog(@"dd");
        
        
        JXAlertview *alert = [[JXAlertview alloc]initWithFrame:CGRectMake(10, 0, kScreenWidth - 60, 200)];
        alert.center = self.view.center;
        alert.delegate = self;
        [alert initwithtitle:@"开始时间" andcommitbtn:@"确定" andStr:@"0"];
        [alert addSubview:self.datePicker];
        [alert show];
        
        
        _mark = 1;
        
        
        
    }//else if (202 == tag){
        
//        JXAlertview *alert = [[JXAlertview alloc]initWithFrame:CGRectMake(10, 0, kScreenWidth - 60, 200)];
//        alert.center = self.view.center;
//        alert.delegate = self;
//        [alert initwithtitle:@"结束时间" andcommitbtn:@"确定" andStr:@"0"];
//        [alert addSubview:self.datePicker];
//        [alert show];
//
//
//        _mark = 2;
    
        
        
    //}
    else{//详情
        ZYResourceSSSSController *vc = [ZYResourceSSSSController new];
         NSString *organizationInfoID = [NSString stringWithFormat:@"%@",[self.organizationInfoDict valueForKey:@"uid"]];//机构uid
        
        vc.ID = organizationInfoID;
        [self.navigationController pushViewController:vc animated:YES];
        
        

    }
    
    
    
    
    
    
    
}




- (void)btnindex:(int)index :(int)tag{
    
    if (index == 2) {
//        if (_mark == 1) {
//            _selectDate = [NSString stringWithFormat:@"%d-%02d-%02d",self.datePicker.year,self.datePicker.month,self.datePicker.day];
//            [self.startSelectButton setTitle:[NSString stringWithFormat:@"%@",_selectDate] forState:(UIControlStateNormal)];
//            _selectDate = [NSString stringWithFormat:@"%d-%02d",self.datePicker.year,self.datePicker.month];
//            [self.startSelectButton setTitle:[NSString stringWithFormat:@"%@",_selectDate] forState:(UIControlStateNormal)];
//        }else if (_mark == 2){
//
//            _selectDate = [NSString stringWithFormat:@"%d-%02d-%02d",self.datePicker.year,self.datePicker.month,self.datePicker.day];
//            [self.endSelectButton setTitle:[NSString stringWithFormat:@"%@",_selectDate] forState:(UIControlStateNormal)];
//        }
        _selectDate = [NSString stringWithFormat:@"%d-%02d",self.datePicker.year,self.datePicker.month];
        [self.startSelectButton setTitle:[NSString stringWithFormat:@"%@",_selectDate] forState:(UIControlStateNormal)];
    }
    
    
    
    
}





#pragma mark --- 确定方法的实现
- (void)sureButtonAction:(UIButton *)sender{
    
//    NSComparisonResult result = [self.startSelectButton.currentTitle compare:self.endSelectButton.currentTitle];
//
//    if (result != NSOrderedAscending) {
//        [SVProgressHUD showErrorWithStatus:@"结束时间必须大于开始时间!"];
//    }else{
//
//                NSString *start = [self.startSelectButton.currentTitle stringByReplacingOccurrencesOfString:@" " withString:@""];
//
//                NSString *endSelect = [self.endSelectButton.currentTitle stringByReplacingOccurrencesOfString:@" " withString:@""];
//
//
//                [self setSetTowSureStart:[self MgrTimeStrFormatterWitStr:start] endSelect:[self MgrTimeStrFormatterWitStr:endSelect]];
//
//    }
    NSString *start = [self.startSelectButton.currentTitle stringByReplacingOccurrencesOfString:@" " withString:@""];
//    NSString *endSelect = [self.endSelectButton.currentTitle stringByReplacingOccurrencesOfString:@" " withString:@""];
    [self setSetTowSureStart:[self MgrTimeStrFormatterWitStr:start] endSelect:[self MgrTimeStrFormatterWitStr:@""]];
    
//    if (![self JudgeBigOrSmallWithBegin:self.startSelectButton.currentTitle End:self.endSelectButton.currentTitle]) {
//
//        [SVProgressHUD showErrorWithStatus:@"结束时间必须大于开始时间!"];
//    } else {
//        // 发起时间查询的请求
//
//
//        NSString *start = [self.startSelectButton.currentTitle stringByReplacingOccurrencesOfString:@" " withString:@""];
//
//        NSString *endSelect = [self.endSelectButton.currentTitle stringByReplacingOccurrencesOfString:@" " withString:@""];
//
//
//        [self setSetTowSureStart:[self MgrTimeStrFormatterWitStr:start] endSelect:[self MgrTimeStrFormatterWitStr:endSelect]];
//
//
//    }
//
    
    
}


- (void)setSetTowSureStart:(NSString *)startStr endSelect:(NSString *)endSelect{
    
    
    self.startTime = startStr;
    self.endTime = endSelect;
    self.isSure = YES;
    self.isSearch = NO;
    
    [self.tableView.mj_header beginRefreshing];
    
}




/** 将2017年10月的格式转成2017-10 */
- (NSString *)MgrTimeStrFormatterWitStr:(NSString *)Str {
    
    Str = [Str stringByReplacingOccurrencesOfString:@"年" withString:@"-"];
    Str = [Str stringByReplacingOccurrencesOfString:@"月" withString:@""];
    return Str;
}







































#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZYResourceCircleTowCell *cell = [tableView dequeueReusableCellWithIdentifier:kCell forIndexPath:indexPath];
    
    if (self.dataSource.count > indexPath.row) {
        
        ZYResourceCircleTowModel *model = self.dataSource[indexPath.row];
        
        [cell assignByZYResourceCircleTowModel:model];
        
    }
    
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    
    return cell;
    
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ZYResourceCircleTowModel *model = [self.dataSource objectAtIndex:indexPath.row];
    
    
    HMElementSortVC *vc = [HMElementSortVC new];
    vc.name = [NSString stringWithFormat:@"%@",model.name];
    
    vc.lessonId = [NSString stringWithFormat:@"%@",model.ID];
    
    
    
    [self.navigationController pushViewController:vc animated:YES];
    
    
    
    
    
    
}








-(void)textFieldDidEndEditing:(UITextField *)textField{
    
    [self.searchTextField resignFirstResponder];
}

//收回键盘
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    [self.searchTextField resignFirstResponder];
    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    if (self.searchTextField.text.length!=0) {
        
        
        if (self.startTime.length != 0 || self.endTime.length != 0) {
            NSLog(@"%@ %@",self.startTime,self.endTime);
        }else{
            self.startTime = [self MgrTimeStrFormatterWitStr:[NSString yearMonthDay]];
            self.endTime = [self MgrTimeStrFormatterWitStr:[NSString yearMonthDay]];
            
        }
        
        
        self.searchName = self.searchTextField.text;
        self.isSearch = YES;
        self.isSure = NO;
        [self.tableView.mj_header beginRefreshing];
        
        
        
        
        
        
        
    }else{
        [MBProgressHUD showError:@"请输入搜索内容"];
    }
    
    return YES;
    
}









/** 判断结束时间是不要大于开始时间 */
- (BOOL)JudgeBigOrSmallWithBegin:(NSString *)Begin End:(NSString *)End {
    
    NSArray *BeginArr = [Begin componentsSeparatedByString:@"年"];
    NSString *BeginMouths = [[BeginArr lastObject] stringByReplacingOccurrencesOfString:@"月" withString:@""];
    NSArray *EndArr = [End componentsSeparatedByString:@"年"];
    NSString *EndMouths = [[EndArr lastObject] stringByReplacingOccurrencesOfString:@"月" withString:@""];
    NSInteger BeginYear = [[BeginArr firstObject] integerValue];
    NSInteger BeginMouth = [BeginMouths integerValue];
    NSInteger EndYear = [[EndArr firstObject] integerValue];
    NSInteger EndMouth = [EndMouths integerValue];
    if (EndYear - BeginYear > 0) {
        
        return YES;
    }
    else if (EndYear - BeginYear == 0 && EndMouth - BeginMouth >= 0) {
        
        return YES;
    } else {
        
        return NO;
    }
}



- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
    [SVProgressHUD dismiss];
    
    
    
}






@end
